package pack04_covid_merge;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


/**
 * @author lilulu
 * @date 2023/2/11 13:16
 */
public class CovidCountReducer extends Reducer<Text,CovidCountBean, Text,CovidCountBean> {
    @Override
    protected void reduce(Text key, Iterable<CovidCountBean> values, Context context) throws IOException, InterruptedException {

        int cases = 0;
        int deaths = 0;
        for (CovidCountBean value : values) {
            cases += value.getCases();
            deaths += value.getDeaths();
        }

        CovidCountBean covidCountBean = new CovidCountBean();
        covidCountBean.setCases(cases);
        covidCountBean.setDeaths(deaths);
        context.write(key,covidCountBean);
    }
}
